package org.csu.small.controller.admin;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.csu.small.common.UniformResponse;
import org.csu.small.entity.Category;
import org.csu.small.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/manage/category/")
@Api(value = "API - CategoryController", description = "分类模块接口详情")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @GetMapping("get_category_info")
    @ResponseBody
    @ApiOperation(value = "获取类别信息")
    public UniformResponse<Category> getCategoryInfo(Integer categoryId){
        UniformResponse<Category> response = categoryService.getCategoryInfo(categoryId);

        return response;
    }

    @GetMapping("delete_category")
    @ResponseBody
    @ApiOperation(value = "获取类别信息")
    public UniformResponse<String> delete_category(Integer categoryId){
        UniformResponse<String> response = categoryService.deleteCategory(categoryId);

        return response;
    }

    @PostMapping("add_category")
    @ResponseBody
    @ApiOperation(value = "新增类别")
    public UniformResponse<String> addCategory(Category category){
        UniformResponse<String> response = categoryService.addCategory(category);

        return response;
    }

    @PostMapping("edit_category")
    @ResponseBody
    @ApiOperation(value = "编辑类别信息")
    public UniformResponse<String> editCategory(Category category){
        UniformResponse<String> response = categoryService.editCategory(category);

        return response;
    }

    @GetMapping("get_category")
    @ResponseBody
    @ApiOperation(value = "获取一层子类")
    public UniformResponse<List<Category>> getCategory(
            @RequestParam(name = "categoryId",defaultValue = "0") Integer categoryId){
        UniformResponse<List<Category>> response = categoryService.getCategory(categoryId);

        return response;
    }

    @GetMapping("get_deep_category")
    @ResponseBody
    @ApiOperation(value = "迭代获取子类")
    public UniformResponse<List<Category>> getDeepCategory(
            @RequestParam(name = "categoryId",defaultValue = "0") Integer categoryId){
        UniformResponse<List<Category>> response = categoryService.getDeepCategory(categoryId);

        return response;
    }
}
